package com.common.util;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ficus
 * 多线程服务
 */
public class ExecutorServiceUtil {

	
	/**
	 * 用时最少放最前面
	 */
	public  static List<Object> submit(List<Callable<Object>> callableList) {
		List<Object> resutList=new ArrayList<Object>();
		ExecutorService exec = Executors.newFixedThreadPool(callableList.size());
		for (Callable<Object> callable : callableList) {
			exec.submit(callable);
		}
		try {
			for (Callable<Object> callable : callableList) {
				Object result;
				try {
					result = callable.call();
					resutList.add(result);
				} catch (Exception e) {
					e.printStackTrace();
					resutList.add(new Object());
				}
			}
		} finally {
			exec.shutdownNow();
		}
		return resutList;
	}
}
